home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Offline Browsing / HTTrack.exe / data1.cab / Sources / src / htswizard.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-28  |  27.8 KB  |  804 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: httrack.c subroutines:                                 */
  34. /*       wizard system (accept/refuse links)                    */
  35. /* Author: Xavier Roche                                         */
  36. /* ------------------------------------------------------------ */
  37.  
  38. #include "htswizard.h"
  39. #include "htsdefines.h"
  40.  
  41. /* specific definitions */
  42. #include "htsbase.h"
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <ctype.h>
  47. /* END specific definitions */
  48.  
  49. // version 1 pour httpmirror
  50. // flusher si on doit lire peu α peu le fichier
  51. #define test_flush if (opt->flush) { fflush(opt->log); fflush(opt->errlog); }
  52.  
  53. // pour allΘger la syntaxe, des raccourcis sont crΘΘs
  54. #define urladr   (liens[ptr]->adr)
  55. #define urlfil   (liens[ptr]->fil)
  56. //#define level    (liens[ptr]->prio)
  57. #define new_stat_bytes (HTS_STAT.HTS_TOTAL_RECV)
  58.  
  59. // libΘrer filters[0] pour insΘrer un ΘlΘment dans filters[0]
  60. #define HT_INSERT_FILTERS0 {\
  61.   int i;\
  62.   if (*filptr > 0) {\
  63.     for(i = (*filptr)-1 ; i>=0 ; i--) {\
  64.       strcpy(filters[i+1],filters[i]);\
  65.     }\
  66.   }\
  67.   strcpy(filters[0],"");\
  68.   (*filptr)++;\
  69.   (*filptr)=minimum((*filptr),filter_max);\
  70. }
  71.  
  72.  
  73.  
  74. /*
  75. httrackp opt     bloc d'options
  76. int ptr,int lien_tot,lien_url** liens
  77.                              relatif aux liens
  78. char* adr,char* fil
  79.                              adresse/fichier α tester
  80. char** filters,int filptr,int filter_max
  81.                              relatif aux filtres
  82. robots_wizard* robots
  83.                              relatif aux robots
  84. int* set_prio_to
  85.                              callback obligatoire "capturer ce lien avec prio=N-1"
  86. int* just_test_it
  87.                              callback optionnel "ne faire que tester ce lien Θventuellement"
  88. retour:
  89.                0 acceptΘ
  90.                1 refusΘ
  91.               -1 pas d'avis
  92. */
  93. int hts_acceptlink(httrackp* opt,
  94.                    int ptr,int lien_tot,lien_url** liens,
  95.                    char* adr,char* fil,
  96.                    char** filters,int* filptr,int filter_max,
  97.                    robots_wizard* robots,
  98.                    int* set_prio_to,
  99.                    int* just_test_it) {
  100.  
  101.   int forbidden_url=-1;
  102.   int meme_adresse;
  103.  
  104.   // -------------------- PHASE 1 --------------------
  105.  
  106.   /* Infos */
  107.   if ((opt->debug>1) && (opt->log!=NULL)) {
  108.     fspc(opt->log,"debug"); fprintf(opt->log,"wizard test begins: %s%s"LF,adr,fil);
  109.     test_flush;
  110.   }
  111.   
  112.   /* Doit-on traiter les non html? */
  113.   if ((opt->getmode & 2)==0) {    // non on ne doit pas
  114.     if (!ishtml(fil)) {  // non il ne faut pas
  115.       //adr[0]='\0';    // ne pas traiter ce lien, pas traiter
  116.       forbidden_url=1;    // interdire rΘcupΘration du lien
  117.       if ((opt->debug>1) && (opt->log!=NULL)) {
  118.         fspc(opt->log,"debug"); fprintf(opt->log,"non-html file ignored at %s : %s"LF,adr,fil);
  119.         test_flush;
  120.       }
  121.       
  122.     }
  123.   }
  124.   
  125.   /* Niveau 1: ne pas parser suivant! */
  126.   if (ptr>0) {
  127.     if (liens[ptr]->depth <= 1) {
  128.       forbidden_url=1;    // interdire rΘcupΘration du lien
  129.       if ((opt->debug>1) && (opt->log!=NULL)) {
  130.         fspc(opt->log,"debug"); fprintf(opt->log,"file from too far level ignored at %s : %s"LF,adr,fil);
  131.         test_flush;
  132.       }
  133.     }
  134.   }
  135.  
  136.   /* en cas d'Θchec en phase 1, retour immΘdiat! */
  137.   if (forbidden_url==1) {
  138.     return forbidden_url;
  139.   }
  140.   
  141.   // -------------------- PHASE 2 --------------------
  142.  
  143.   // ------------------------------------------------------
  144.   // doit-on traiter ce lien?.. vΘrifier droits de dΘplacement
  145.   meme_adresse=strfield2(adr,urladr);
  146.   if ((opt->debug>1) && (opt->log!=NULL)) {
  147.     fspc(opt->log,"debug"); 
  148.     if (meme_adresse) 
  149.       fprintf(opt->log,"Compare addresses: %s=%s"LF,adr,urladr);
  150.     else
  151.       fprintf(opt->log,"Compare addresses: %s!=%s"LF,adr,urladr);
  152.     test_flush;
  153.   }
  154.   if (meme_adresse) {  // mΩme adresse 
  155.     {  // tester interdiction de descendre
  156.       // MODIFIE : en cas de remontΘe puis de redescente, il se pouvait qu'on ne puisse pas atteindre certains fichiers
  157.       // problΦme: si un fichier est virtuellement accessible via une page mais dont le lien est sur une autre *uniquement*..
  158.       char tempo[HTS_URLMAXSIZE*2];
  159.       char tempo2[HTS_URLMAXSIZE*2];
  160.       
  161.       // note (up/down): on calcule α partir du lien primaire, ET du lien prΘcΘdent.
  162.       // ex: si on descend 2 fois on peut remonter 1 fois
  163.       
  164.       if (lienrelatif(tempo,fil,liens[liens[ptr]->premier]->fil)==0) {
  165.         if (lienrelatif(tempo2,fil,liens[ptr]->fil)==0) {
  166.           if ((opt->debug>1) && (opt->log!=NULL)) {
  167.             fspc(opt->log,"debug"); fprintf(opt->log,"build relative links to test: %s %s (with %s and %s)"LF,tempo,tempo2,liens[liens[ptr]->premier]->fil,liens[ptr]->fil);
  168.             test_flush;
  169.           }
  170.           
  171.           // si vient de primary, ne pas tester lienrelatif avec (car host "diffΘrent")
  172.           /*if (liens[liens[ptr]->premier] == 0) {   // vient de primary
  173.           }
  174.           */
  175.           
  176.           // NEW: finalement OK, sauf pour les moved repΘrΘs par link_import
  177.           // PROBLEME : annulΘ a cause d'un lien Θventuel isolΘ acceptΘ..qui entrainerait un miroir
  178.           
  179.           // (test mΩme niveau (NOUVEAU α cause de certains problΦmes de filtres non intΘgrΘs))
  180.           // NEW
  181.           if ( (!strchr(tempo+1,'/')) || (!strchr(tempo2+1,'/')) ) {
  182.             if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  183.               forbidden_url=0;
  184.               if ((opt->debug>1) && (opt->log!=NULL)) {
  185.                 fspc(opt->log,"debug"); fprintf(opt->log,"same level link authorized: %s%s"LF,adr,fil);
  186.                 test_flush;
  187.               }
  188.             }
  189.           }
  190.           
  191.           // down
  192.           if ( (strncmp(tempo,"../",3)) || (strncmp(tempo2,"../",3)))  {   // pas montΘe sinon ne nbous concerne pas
  193.             int test1,test2;
  194.             if (!strncmp(tempo,"../",3))
  195.               test1=0;
  196.             else
  197.               test1 = (strchr(tempo +((*tempo =='/')?1:0),'/')!=NULL);
  198.             if (!strncmp(tempo2,"../",3))
  199.               test2=0;
  200.             else
  201.               test2 = (strchr(tempo2+((*tempo2=='/')?1:0),'/')!=NULL);
  202.             if ( (test1) && (test2) ) {   // on ne peut que descendre
  203.               if ((opt->seeker & 1)==0) {  // interdiction de descendre
  204.                 forbidden_url=1;
  205.                 if ((opt->debug>1) && (opt->log!=NULL)) {
  206.                   fspc(opt->log,"debug"); fprintf(opt->log,"lower link canceled: %s%s"LF,adr,fil);
  207.                   test_flush;
  208.                 }
  209.               } else {    // autorisΘ α priori - NEW
  210.                 if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  211.                   forbidden_url=0;
  212.                   if ((opt->debug>1) && (opt->log!=NULL)) {
  213.                     fspc(opt->log,"debug"); fprintf(opt->log,"lower link authorized: %s%s"LF,adr,fil);
  214.                     test_flush;
  215.                   }
  216.                 }
  217.               }
  218.             } else if ( (test1) || (test2) ) {   // on peut descendre pour accΘder au lien
  219.               if ((opt->seeker & 1)!=0) {  // on peut descendre - NEW
  220.                 if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  221.                   forbidden_url=0;
  222.                   if ((opt->debug>1) && (opt->log!=NULL)) {
  223.                     fspc(opt->log,"debug"); fprintf(opt->log,"lower link authorized: %s%s"LF,adr,fil);
  224.                     test_flush;
  225.                   }
  226.                 }
  227.               }
  228.             }
  229.           }
  230.           
  231.           
  232.           // up
  233.           if ( (!strncmp(tempo,"../",3)) && (!strncmp(tempo2,"../",3)) ) {    // impossible sans monter
  234.             if ((opt->seeker & 2)==0) {  // interdiction de monter
  235.               forbidden_url=1;
  236.               if ((opt->debug>1) && (opt->log!=NULL)) {
  237.                 fspc(opt->log,"debug"); fprintf(opt->log,"upper link canceled: %s%s"LF,adr,fil);
  238.                 test_flush;
  239.               }
  240.             } else {       // autorisΘ α monter - NEW
  241.               if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  242.                 forbidden_url=0;
  243.                 if ((opt->debug>1) && (opt->log!=NULL)) {
  244.                   fspc(opt->log,"debug"); fprintf(opt->log,"upper link authorized: %s%s"LF,adr,fil);
  245.                   test_flush;
  246.                 }
  247.               }
  248.             }
  249.           } else if ( (!strncmp(tempo,"../",3)) || (!strncmp(tempo2,"../",3)) ) {    // Possible en montant
  250.             if ((opt->seeker & 2)!=0) {  // autorisΘ α monter - NEW
  251.               if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  252.                 forbidden_url=0;
  253.                 if ((opt->debug>1) && (opt->log!=NULL)) {
  254.                   fspc(opt->log,"debug"); fprintf(opt->log,"upper link authorized: %s%s"LF,adr,fil);
  255.                   test_flush;
  256.                 }
  257.               }
  258.             }  // sinon autorisΘ en descente
  259.           }
  260.           
  261.           
  262.         } else {
  263.           if (opt->errlog) {
  264.             fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[ptr]->fil);
  265.             test_flush;
  266.           }
  267.         }
  268.       } else {
  269.         if (opt->errlog) {
  270.           fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[liens[ptr]->premier]->fil);
  271.           test_flush;
  272.         }
  273.       }
  274.       
  275.     }  // tester interdiction de descendre?
  276.     
  277.     {  // tester interdiction de monter
  278.       char tempo[HTS_URLMAXSIZE*2];
  279.       char tempo2[HTS_URLMAXSIZE*2];
  280.       if (lienrelatif(tempo,fil,liens[liens[ptr]->premier]->fil)==0) {
  281.         if (lienrelatif(tempo2,fil,liens[ptr]->fil)==0) {
  282.         } else {
  283.           if (opt->errlog) { 
  284.             fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[ptr]->fil);
  285.             test_flush;
  286.           }
  287.           
  288.         }
  289.       } else {
  290.         if (opt->errlog) { 
  291.           fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[liens[ptr]->premier]->fil);
  292.           test_flush;
  293.         }
  294.         
  295.       }
  296.     }   // fin tester interdiction de monter
  297.     
  298.   } else {    // adresse diffΘrente, sortir?
  299.     
  300.     //if (!opt->wizard) {    // mode non wizard
  301.     // doit-on traiter ce lien?.. vΘrifier droits de sortie
  302.     switch((opt->travel & 255)) {
  303.     case 0: 
  304.       if (!opt->wizard)    // mode non wizard
  305.         forbidden_url=1; break;    // interdicton de sortir au dela de l'adresse
  306.     case 1: {              // sortie sur le mΩme dom.xxx
  307.       int i=strlen(adr)-1;
  308.       int j=strlen(urladr)-1;
  309.       while( (i>0) && (adr[i]!='.')) i--;
  310.       while( (j>0) && (urladr[j]!='.')) j--;
  311.       i--; j--;
  312.       while( (i>0) && (adr[i]!='.')) i--;
  313.       while( (j>0) && (urladr[j]!='.')) j--;
  314.       if ((i>0) && (j>0)) {
  315.         if (!strfield2(adr+i,urladr+j)) {   // !=
  316.           if (!opt->wizard) {   // mode non wizard
  317.             //printf("refused: %s\n",adr);
  318.             forbidden_url=1;  // pas mΩme domaine  
  319.             if ((opt->debug>1) && (opt->log!=NULL)) {
  320.               fspc(opt->log,"debug"); fprintf(opt->log,"foreign domain link canceled: %s%s"LF,adr,fil);
  321.               test_flush;
  322.             }
  323.           }
  324.           
  325.         } else {
  326.           if (opt->wizard) {   // mode wizard
  327.             forbidden_url=0;  // mΩme domaine  
  328.             if ((opt->debug>1) && (opt->log!=NULL)) {
  329.               fspc(opt->log,"debug"); fprintf(opt->log,"same domain link authorized: %s%s"LF,adr,fil);
  330.               test_flush;
  331.             }
  332.           }
  333.         }
  334.         
  335.       } else
  336.         forbidden_url=1;
  337.             } 
  338.       break;  
  339.     case 2: {                      // sortie sur le mΩme .xxx
  340.       int i=strlen(adr)-1;
  341.       int j=strlen(urladr)-1;
  342.       while( (i>0) && (adr[i]!='.')) i--;
  343.       while( (j>0) && (urladr[j]!='.')) j--;
  344.       if ((i>0) && (j>0)) {
  345.         if (!strfield2(adr+i,urladr+j)) {   // !-
  346.           if (!opt->wizard) {   // mode non wizard
  347.             //printf("refused: %s\n",adr);
  348.             forbidden_url=1;  // pas mΩme .xx  
  349.             if ((opt->debug>1) && (opt->log!=NULL)) {
  350.               fspc(opt->log,"debug"); fprintf(opt->log,"foreign location link canceled: %s%s"LF,adr,fil);
  351.               test_flush;
  352.             }
  353.           }
  354.         } else {
  355.           if (opt->wizard) {   // mode wizard
  356.             forbidden_url=0;  // mΩme domaine  
  357.             if ((opt->debug>1) && (opt->log!=NULL)) {
  358.               fspc(opt->log,"debug"); fprintf(opt->log,"same location link authorized: %s%s"LF,adr,fil);
  359.               test_flush;
  360.             }
  361.           }
  362.         }
  363.       } else forbidden_url=1;     
  364.             } 
  365.       break;
  366.     case 7:                 // everywhere!!
  367.       if (opt->wizard) {   // mode wizard
  368.         forbidden_url=0;
  369.         break;
  370.       }
  371.     }  // switch
  372.     
  373.     // ANCIENNE POS -- rΘcupΘrer les liens α c⌠tΘs d'un lien (nearlink)
  374.     
  375.   }  // fin test adresse identique/diffΘrente
  376.  
  377.   // -------------------- PHASE 3 --------------------
  378.  
  379.   // rΘcupΘrer les liens α c⌠tΘs d'un lien (nearlink) (nvelle pos)
  380.   if (opt->nearlink) {
  381.     if (!ishtml(fil)) {  // non html
  382.       //printf("ok %s%s\n",ad,fil);
  383.       forbidden_url=0;    // autoriser
  384.       if ((opt->debug>1) && (opt->log!=NULL)) {
  385.         fspc(opt->log,"debug"); fprintf(opt->log,"near link authorized: %s%s"LF,adr,fil);
  386.         test_flush;
  387.       }
  388.     }
  389.   }
  390.   
  391.   // -------------------- PHASE 4 --------------------
  392.   
  393.   // ------------------------------------------------------
  394.   // Si wizard, il se peut qu'on autorise ou qu'on interdise 
  395.   // un lien spΘcial avant mΩme de tester sa position, sa hiΘrarchie etc.
  396.   // peut court-circuiter le forbidden_url prΘcΘdent
  397.   if (opt->wizard) { // le wizard entre en action..
  398.     //
  399.     int jok;
  400.     int question=1;         // poser une question                            
  401.     int force_mirror=0;     // pour mirror links
  402.     int filters_answer=0;   // dΘcision prise par les filtres
  403.     char l[HTS_URLMAXSIZE*2];
  404.     
  405.     if (forbidden_url!=-1) question=0;  // pas de question, rΘsolu
  406.     
  407.     // former URL complΦte du lien actuel
  408.     strcpy(l,jump_identification(adr));
  409.     if (*fil!='/') strcat(l,"/");
  410.     strcat(l,fil);
  411.     
  412.     // tester filters (URLs autorisΘes ou interdites explicitement)
  413.     
  414.     // si lien primaire on saute le joker, on est pas lΘmur
  415.     if (ptr==0) {  // lien primaire, autoriser
  416.       question=1;    // la question sera rΘsolue automatiquement
  417.       forbidden_url=0;
  418.     } else {
  419.       // filters, 0=sait pas 1=ok -1=interdit
  420.       jok = fa_strjoker(filters,*filptr,l,NULL,NULL);
  421.       if (jok == 1) {   // autorisΘ
  422.         filters_answer=1;  // dΘcision prise par les filtres
  423.         question=0;    // ne pas poser de question, autorisΘ
  424.         forbidden_url=0;  // URL autorisΘe
  425.         if ((opt->debug>1) && (opt->log!=NULL)) {
  426.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) explicit authorized link: link %s at %s%s"LF,l,urladr,urlfil);
  427.           test_flush;
  428.         }
  429.       } else if (jok == -1) {
  430.         filters_answer=1;  // dΘcision prise par les filtres
  431.         question=0;    // ne pas poser de question:
  432.         forbidden_url=1;   // URL interdite
  433.         if ((opt->debug>1) && (opt->log!=NULL)) {
  434.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) explicit forbidden link: link %s at %s%s"LF,l,urladr,urlfil);
  435.           test_flush;
  436.         }
  437.       }  // sinon on touche α rien
  438.     }
  439.     
  440.     // vΘrifier mode mirror links
  441.     if (question) {
  442.       if (opt->mirror_first_page) {    // mode mirror links
  443.         if (liens[ptr]->precedent==0) {  // parent=primary!
  444.           forbidden_url=0;    // autorisΘ
  445.           question=1;         // rΘsolution auto
  446.           force_mirror=5;     // mirror (5)
  447.           if ((opt->debug>1) && (opt->log!=NULL)) {
  448.             fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) explicit mirror link: link %s at %s%s"LF,l,urladr,urlfil);
  449.             test_flush;
  450.           }
  451.         }
  452.       }
  453.     }
  454.  
  455.     // vΘrifier rΘcursivitΘ extΘrieure
  456.     if ((question) && (ptr>0) && (!force_mirror)) {
  457.       if (opt->extdepth>0) {
  458.         *set_prio_to = opt->extdepth + 1;
  459.         forbidden_url=0;    // autorisΘ
  460.         question=0;         // rΘsolution auto
  461.         if ((opt->debug>1) && (opt->log!=NULL)) {
  462.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) ambiguous link accepted (external depth): link %s at %s%s"LF,l,urladr,urlfil);
  463.           test_flush;
  464.         }
  465.       }
  466.     }  
  467.     
  468.     // on doit poser la question.. peut on la poser?
  469.     // (oui je sais quel preuve de dΘlicatesse, merci merci)      
  470.     if ((question) && (ptr>0) && (!force_mirror)) {
  471.       if (opt->wizard==2) {    // Θliminer tous les liens non rΘpertoriΘs comme autorisΘs (ou inconnus)
  472.         question=0;
  473.         forbidden_url=1;
  474.         if ((opt->debug>1) && (opt->log!=NULL)) {
  475.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) ambiguous forbidden link: link %s at %s%s"LF,l,urladr,urlfil);
  476.           test_flush;
  477.         }
  478.       }
  479.     }
  480.     
  481.     // vΘrifier robots.txt
  482.     if (opt->robots) {
  483.       int r = checkrobots(robots,adr,fil);
  484.       if (r == -1) {    // interdiction
  485. #if DEBUG_ROBOTS
  486.         printf("robots.txt forbidden: %s%s\n",adr,fil);
  487. #endif
  488.         // question rΘsolue, par les filtres, et mode robot non strict
  489.         if ((!question) && (filters_answer) && (opt->robots == 1) && (forbidden_url!=1)) {
  490.           r=0;    // annuler interdiction des robots
  491.           if (!forbidden_url) {
  492.             if ((opt->debug>1) && (opt->log!=NULL)) {
  493.               fspc(opt->log,"debug"); fprintf(opt->log,"Warning link followed against robots.txt: link %s at %s%s"LF,l,adr,fil);
  494.               test_flush;
  495.             }
  496.           }
  497.         }
  498.         if (r == -1) {    // interdire
  499.           forbidden_url=1;
  500.           question=0;
  501.           if ((opt->debug>1) && (opt->log!=NULL)) {
  502.             fspc(opt->log,"debug"); fprintf(opt->log,"(robots.txt) forbidden link: link %s at %s%s"LF,l,adr,fil);
  503.             test_flush;
  504.           }
  505.         }
  506.       }
  507.     }
  508.     
  509.     if (!question) {
  510.       if ((opt->debug>1) && (opt->log!=NULL)) {
  511.         if (!forbidden_url) {
  512.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) shared foreign domain link: link %s at %s%s"LF,l,urladr,urlfil);
  513.         } else {
  514.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) cancelled foreign domain link: link %s at %s%s"LF,l,urladr,urlfil);
  515.         }
  516.         test_flush;
  517.       }
  518. #if BDEBUG==3
  519.       printf("at %s in %s, wizard says: url %s ",urladr,urlfil,l);
  520.       if (forbidden_url) printf("cancelled"); else printf(">SHARED<");
  521.       printf("\n");
  522. #endif 
  523.     }
  524.  
  525.     /* en cas de question, ou lien primaire (enregistrer autorisations) */
  526.     if (question || (ptr==0)) {
  527. #if HTS_ANALYSTE!=2
  528.       char s[4];
  529. #else
  530.       char* s;
  531. #endif
  532.       int n=0;
  533.       
  534.       // si primaire (plus bas) alors ...
  535.       if ((ptr!=0) && (force_mirror==0)) {
  536.         HTS_REQUEST_START;
  537.         HT_PRINT("\n");
  538.         HT_PRINT("At "); HT_PRINT(urladr); HT_PRINT(", there is a link ("); HT_PRINT(adr); HT_PRINT("/"); HT_PRINT(fil); HT_PRINT(") which goes outside the address."LF);
  539.         HT_PRINT("What should I do? (press a key + enter)"LF LF);
  540.         HT_PRINT("* Ignore all further links" LF);
  541.         HT_PRINT("0 Ignore this link (default if empty entry)"LF);
  542.         HT_PRINT("1 Ignore directory and lower structures"LF);
  543.         HT_PRINT("2 Ignore all domain"LF);
  544.         //HT_PRINT("3 (Ignore location, not implemented)\n");
  545.         HT_PRINT(LF);
  546.         HT_PRINT("4 Get only this page/link"LF);
  547.         HT_PRINT("5 Mirror this link (useful)"LF);
  548.         HT_PRINT("6 Mirror links located in the same domain"LF);
  549.         HT_PRINT(LF);
  550. #if HTS_ANALYSTE!=2
  551.         //HT_PRINT("! View extract of html code where the link is located"LF);
  552. #endif
  553.         HTS_REQUEST_END;
  554. #if HTS_ANALYSTE!=2
  555.         do {
  556.           io_flush; linput(stdin,s,2);
  557. #else
  558.           {
  559.             char tempo[HTS_URLMAXSIZE*2];
  560.             tempo[0]='\0';
  561.             strcat(tempo,adr);
  562.             strcat(tempo,"/");
  563.             strcat(tempo,fil);
  564.             s=hts_htmlcheck_query3(tempo);
  565.           }
  566. #endif
  567.           if (strnotempty(s)==0)  // entrΘe
  568.             n=0;
  569.           else if (isdigit((unsigned char)*s))
  570.             sscanf(s,"%d",&n);
  571.           else {
  572.             switch(*s) {
  573.             case '*': n=-1; break;
  574.             case '!': n=-999; {
  575.               /*char *a;
  576.               int i;                                    
  577.               a=copie_de_adr-128;
  578.               if (a<r.adr) a=r.adr;
  579.               for(i=0;i<256;i++) {
  580.                 if (a==copie_de_adr) printf("\nHERE:\n");
  581.                 printf("%c",*a++);
  582.               }
  583.               printf("\n\n");
  584.               */
  585.                       }
  586.               break;
  587.             default: n=-999; printf("What did you say?\n"); break;
  588.               
  589.             } 
  590.           }
  591. #if HTS_ANALYSTE!=2                                                              
  592.         } while(n==-999);
  593. #endif
  594.         io_flush;
  595.       } else {   // lien primaire: autoriser rΘpertoire entier
  596.         if (!force_mirror) {
  597.           if ((opt->seeker & 1)==0) {  // interdiction de descendre
  598.             n=7;
  599.           } else {
  600.             n=5;   // autoriser miroir rΘpertoires descendants (lien primaire)
  601.           }
  602.         } else   // forcer valeur (sub-wizard)
  603.           n=force_mirror;
  604.       }
  605.       
  606.       switch(n) {
  607.       case -1: // sauter tout le reste
  608.         forbidden_url=1;
  609.         opt->wizard=2;    // sauter tout le reste
  610.         break;
  611.       case 0:    // interdire les mΩmes liens: adr/fil
  612.         forbidden_url=1; 
  613.         HT_INSERT_FILTERS0;    // insΘrer en 0
  614.         strcpy(filters[0],"-");
  615.         strcat(filters[0],jump_identification(adr));
  616.         if (*fil!='/') strcat(filters[0],"/");
  617.         strcat(filters[0],fil);
  618.         break;
  619.         
  620.       case 1: // Θliminer rΘpertoire entier et sous rΘp: adr/path/ *
  621.         forbidden_url=1;
  622.         {
  623.           int i=strlen(fil)-1;
  624.           while((fil[i]!='/') && (i>0)) i--;
  625.           if (fil[i]=='/') {
  626.             HT_INSERT_FILTERS0;    // insΘrer en 0
  627.             strcpy(filters[0],"-");
  628.             strcat(filters[0],jump_identification(adr));
  629.             if (*fil!='/') strcat(filters[0],"/");
  630.             strncat(filters[0],fil,i);
  631.             if (filters[0][strlen(filters[0])-1]!='/') strcat(filters[0],"/");
  632.             strcat(filters[0],"*");
  633.           }
  634.         }            
  635.         
  636.         // ** ...
  637.         break;
  638.         
  639.       case 2:    // adresse adr*
  640.         forbidden_url=1;
  641.         HT_INSERT_FILTERS0;    // insΘrer en 0                                
  642.         strcpy(filters[0],"-");
  643.         strcat(filters[0],jump_identification(adr));
  644.         strcat(filters[0],"*");
  645.         break;
  646.         
  647.       case 3: // ** A FAIRE
  648.         forbidden_url=1;
  649.         /*
  650.         {
  651.         int i=strlen(adr)-1;
  652.         while((adr[i]!='/') && (i>0)) i--;
  653.         if (i>0) {
  654.         
  655.           }
  656.           
  657.       }*/
  658.         
  659.         break;
  660.         //
  661.       case 4:    // same link
  662.         // PAS BESOIN!!
  663.         /*HT_INSERT_FILTERS0;    // insΘrer en 0                                
  664.         strcpy(filters[0],"+");
  665.         strcat(filters[0],adr);
  666.         if (*fil!='/') strcat(filters[0],"/");
  667.         strcat(filters[0],fil);*/
  668.         
  669.         
  670.         // Θtant donnΘ le renversement wizard/primary filter (les primary autorisent up/down ET interdisent)
  671.         // il faut Θviter d'un lien isolΘ effectue un miroir total..
  672.         
  673.         *set_prio_to = 0+1;    // niveau de rΘcursion=0 (pas de miroir)
  674.         
  675.         break;
  676.         
  677.       case 5:    // autoriser rΘpertoire entier et fils
  678.         if ((opt->seeker & 2)==0) {  // interdiction de monter
  679.           int i=strlen(fil)-1;
  680.           while((fil[i]!='/') && (i>0)) i--;
  681.           if (fil[i]=='/') {
  682.             HT_INSERT_FILTERS0;    // insΘrer en 0                                
  683.             strcpy(filters[0],"+");
  684.             strcat(filters[0],jump_identification(adr));
  685.             if (*fil!='/') strcat(filters[0],"/");
  686.             strncat(filters[0],fil,i+1);
  687.             strcat(filters[0],"*");
  688.           }
  689.         } else {    // autoriser domaine alors!!
  690.           HT_INSERT_FILTERS0;    // insΘrer en 0                                strcpy(filters[filptr],"+");
  691.           strcpy(filters[0],"+");
  692.           strcat(filters[0],jump_identification(adr));
  693.           strcat(filters[0],"*");
  694.         }
  695.         break;
  696.         
  697.       case 6:    // same domain
  698.         HT_INSERT_FILTERS0;    // insΘrer en 0                                strcpy(filters[filptr],"+");
  699.         strcpy(filters[0],"+");
  700.         strcat(filters[0],jump_identification(adr));
  701.         strcat(filters[0],"*");
  702.         break;
  703.         //
  704.       case 7:    // autoriser ce rΘpertoire
  705.         {
  706.           int i=strlen(fil)-1;
  707.           while((fil[i]!='/') && (i>0)) i--;
  708.           if (fil[i]=='/') {
  709.             HT_INSERT_FILTERS0;    // insΘrer en 0                                
  710.             strcpy(filters[0],"+");
  711.             strcat(filters[0],jump_identification(adr));
  712.             if (*fil!='/') strcat(filters[0],"/");
  713.             strncat(filters[0],fil,i+1);
  714.             strcat(filters[0],"*[file]");
  715.           }
  716.         }
  717.         
  718.         break;
  719.         
  720.       case 50:    // on fait rien
  721.         break;
  722.       }  // switch 
  723.                               
  724.     }  // test du wizard sur l'url
  725.   }  // fin du test wizard..
  726.  
  727.   // -------------------- PHASE 5 --------------------
  728.  
  729.   // lien non autorisΘ, peut-on juste le tester?
  730.   if (just_test_it) {
  731.     if (forbidden_url==1) {
  732.       if (opt->travel&256) {    // tester tout de mΩme
  733.         if (strfield(adr,"ftp://")==0) {    // PAS ftp!
  734.           forbidden_url=1;    // oui oui toujours interdit (note: sert α rien car ==1 mais c pour comprendre)
  735.           *just_test_it=1;     // mais on teste
  736.           if ((opt->debug>1) && (opt->log!=NULL)) {
  737.             fspc(opt->log,"debug"); fprintf(opt->log,"Testing link %s%s"LF,adr,fil);
  738.           }
  739.         }
  740.       }
  741.     }
  742.     //adr[0]='\0';  // cancel
  743.   }
  744.  
  745.   // -------------------- PHASE 6 --------------------
  746. #if HTS_ANALYSTE==2
  747.   {
  748.     int test_url=hts_htmlcheck_check(adr,fil,forbidden_url);
  749.     if (test_url!=-1)
  750.       forbidden_url=test_url;
  751.   }
  752. #endif  
  753.   return forbidden_url;
  754. }
  755.  
  756. // tester taille
  757. int hts_testlinksize(httrackp* opt,
  758.                      char* adr,char* fil,
  759.                      LLint size) {
  760.   int jok=0;
  761.   if (size>=0) {
  762.     char l[HTS_URLMAXSIZE*2];
  763.     if (size>=0) {
  764.       LLint sz=size;
  765.       int size_flag=0;
  766.       
  767.       // former URL complΦte du lien actuel
  768.       strcpy(l,jump_identification(adr));
  769.       if (*fil!='/') strcat(l,"/");
  770.       strcat(l,fil);
  771.       
  772.       // tester filtres (taille)
  773.       jok = fa_strjoker(opt->filters.filters,*opt->filters.filptr,l,&sz,&size_flag);
  774.       
  775.       // log
  776.       if (jok==1) {
  777.         if ((opt->debug>1) && (opt->log!=NULL)) {
  778.           fspc(opt->log,"debug"); fprintf(opt->log,"File confirmed (size test): %s%s ("LLintP")"LF,adr,fil,(LLint)(size));
  779.         }
  780.       } else if (jok==-1) {
  781.         if (size_flag) {        /* interdit α cause de la taille */
  782.           if ((opt->debug>1) && (opt->log!=NULL)) {
  783.             fspc(opt->log,"debug"); fprintf(opt->log,"File cancelled due to its size: %s%s ("LLintP", limit: "LLintP")"LF,adr,fil,(LLint)(size),(LLint)(sz));
  784.           }
  785.         } else {
  786.           jok=1;
  787.         }
  788.       }
  789.     }
  790.   }
  791.   return jok;
  792. }
  793.  
  794.  
  795.  
  796. #undef test_flush
  797. #undef urladr
  798. #undef urlfil
  799. //#undef level
  800. #undef new_stat_bytes
  801.  
  802. #undef HT_INSERT_FILTERS0
  803.  
  804.